package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.product.ProductStockDto;
import com.java110.intf.goods.IProductStockInnerServiceSMO;
import com.java110.mall.goods.dao.IProductStockServiceDao;
import com.java110.po.product.ProductStockPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 商品库存内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class ProductStockInnerServiceSMOImpl extends BaseServiceSMO implements IProductStockInnerServiceSMO {

    @Autowired
    private IProductStockServiceDao productStockServiceDaoImpl;


    @Override
    public int saveProductStock(@RequestBody ProductStockPo productStockPo) {
        int saveFlag = 1;
        productStockServiceDaoImpl.saveProductStockInfo(BeanConvertUtil.beanCovertMap(productStockPo));
        return saveFlag;
    }

    @Override
    public int updateProductStock(@RequestBody ProductStockPo productStockPo) {
        int saveFlag = 1;
        productStockServiceDaoImpl.updateProductStockInfo(BeanConvertUtil.beanCovertMap(productStockPo));
        return saveFlag;
    }

    @Override
    public int deleteProductStock(@RequestBody ProductStockPo productStockPo) {
        int saveFlag = 1;
        productStockPo.setStatusCd("1");
        productStockServiceDaoImpl.updateProductStockInfo(BeanConvertUtil.beanCovertMap(productStockPo));
        return saveFlag;
    }

    @Override
    public List<ProductStockDto> queryProductStocks(@RequestBody ProductStockDto productStockDto) {

        //校验是否传了 分页信息

        int page = productStockDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            productStockDto.setPage((page - 1) * productStockDto.getRow());
        }

        List<ProductStockDto> productStocks = BeanConvertUtil.covertBeanList(productStockServiceDaoImpl.getProductStockInfo(BeanConvertUtil.beanCovertMap(productStockDto)), ProductStockDto.class);

        return productStocks;
    }


    @Override
    public int queryProductStocksCount(@RequestBody ProductStockDto productStockDto) {
        return productStockServiceDaoImpl.queryProductStocksCount(BeanConvertUtil.beanCovertMap(productStockDto));
    }

    public IProductStockServiceDao getProductStockServiceDaoImpl() {
        return productStockServiceDaoImpl;
    }

    public void setProductStockServiceDaoImpl(IProductStockServiceDao productStockServiceDaoImpl) {
        this.productStockServiceDaoImpl = productStockServiceDaoImpl;
    }
}
